package com.zhiche.lisa.lspm.service.sys.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zhiche.lisa.lspm.dao.mapper.sys.UserMapper;
import com.zhiche.lisa.lspm.dao.model.sys.User;
import com.zhiche.lisa.lspm.service.sys.IRoleService;
import com.zhiche.lisa.lspm.service.sys.IUserRoleService;
import com.zhiche.lisa.lspm.service.sys.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Objects;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author liuanshun
 * @since 2018-09-28
 */
@Service
public class UserServiceDiy extends ServiceImpl<UserMapper, User> implements IUserService {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserServiceDiy.class);

    @Autowired
    IUserRoleService userRoleService;

    @Autowired
    IRoleService roleService;

    @Override
    public synchronized void addUser(User user) {
        Wrapper<User> userWrapper =new EntityWrapper();
        userWrapper.eq("mobile",user.getMobile());
        User selectOne = this.selectOne(userWrapper);
        if (Objects.isNull(selectOne)) {
            user.setCode(String.valueOf(new Date().getTime()));
            LOGGER.info("UserServiceDiy addUser params:{}", JSONObject.toJSONString(user));
            this.insert(user);
        }
    }
}
